package annTrain;


public class ResultError {
	
	double totalMSE = 0;
	double range = 1;
	int totalCount = 0;
	public int NumErrors = 0;
	
	public ResultError(double range)
	{
		this.range = range;
	}
	
	public void Reset()
	{
		totalMSE = 0;
		totalCount = 0;
	}
	
	public double GetMSE()
	{
		return totalMSE / (double)totalCount;
	}
	
	public double AddResult(double[] targets, double[] outputs)
	{
		if (targets.length != outputs.length)
			return -1;
		else
		{
			double squareSums = 0;
			for (int i = 0; i < targets.length; i++)
			{
				squareSums += Math.pow((targets[i] - outputs[i]) / range, 2);
			}
			squareSums /= outputs.length;
			totalMSE += squareSums;
			totalCount ++;
			return totalMSE / (double)totalCount;
		}
		
	}
	
}
